package com.ruoyi.web.controller.company;

import java.util.List;

import com.ruoyi.common.annotation.Anonymous;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.advantage.domain.Advantage;
import com.ruoyi.advantage.service.IAdvantageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 企业优势Controller
 *
 * @author ruoyi
 * @date 2025-05-28
 */
@RestController
@RequestMapping("/advantage/advantage")
public class AdvantageController extends BaseController
{
    @Autowired
    private IAdvantageService advantageService;

    /**
     * 查询企业优势列表
     */
    @PreAuthorize("@ss.hasPermi('advantage:advantage:list')")
    @GetMapping("/list")
    public TableDataInfo list(Advantage advantage)
    {
        startPage();
        List<Advantage> list = advantageService.selectAdvantageList(advantage);
        return getDataTable(list);
    }

    /**
     * 导出企业优势列表
     */
    @PreAuthorize("@ss.hasPermi('advantage:advantage:export')")
    @Log(title = "企业优势", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Advantage advantage)
    {
        List<Advantage> list = advantageService.selectAdvantageList(advantage);
        ExcelUtil<Advantage> util = new ExcelUtil<Advantage>(Advantage.class);
        util.exportExcel(response, list, "企业优势数据");
    }

    /**
     * 获取企业优势详细信息
     */
    @PreAuthorize("@ss.hasPermi('advantage:advantage:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(advantageService.selectAdvantageById(id));
    }

    /**
     * 新增企业优势
     */
    @PreAuthorize("@ss.hasPermi('advantage:advantage:add')")
    @Log(title = "企业优势", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Advantage advantage)
    {
        return toAjax(advantageService.insertAdvantage(advantage));
    }

    /**
     * 修改企业优势
     */
    @PreAuthorize("@ss.hasPermi('advantage:advantage:edit')")
    @Log(title = "企业优势", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Advantage advantage)
    {
        return toAjax(advantageService.updateAdvantage(advantage));
    }

    /**
     * 删除企业优势
     */
    @PreAuthorize("@ss.hasPermi('advantage:advantage:remove')")
    @Log(title = "企业优势", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(advantageService.deleteAdvantageByIds(ids));
    }

    @Anonymous
    @GetMapping("/getInfo")
    public TableDataInfo getInfo(Advantage advantage){
        startPage();
        List<Advantage>list = advantageService.selectAdvantageList(advantage);
        return getDataTable(list);
    }

}

